from django.test import TestCase, Client

class MyTests(TestCase):
    def setUp(self):
        self.client = Client()
        
    def get_of_csrftoken(self):
        response = self.client.get('/news/login/')
        csrf_no = response.content.index('csrfmiddlewaretoken')
        return response.content[csrf_no:csrf_no + 66].split("'")[2]

    def test_get_2_csrf(self):
        csrf = self.get_of_csrftoken()
        print "DEBUG:%d(%s)" % (len(csrf), csrf)
        response = self.client.post('/news/login/',
                                    {'csrfmiddlewaretoken': csrf,
                                     'full_name': 'love',
                                     'password': 'a112B112',
                                     },)
        print response.content[200:600]
        #self.assertContains(response, "username or password is error")
        self.assertContains(response, "Successed")  #?????? post if wrong
        ###Test of login(post) is FAILED????????
        ###and post to '/admin/' is same problem
        ###see at 'user_contacts/tests/test_login_admin_route' ???


    def test_login_csrf(self):
        #csrf = self.get_of_csrftoken()
        #print "DEBUG:%d(%s)" % (len(csrf), csrf)
        response = self.client.login(username='admin',
                                     password='admin')
        self.assertEqual(response, True)
